home *** CD-ROM | disk | FTP | other *** search
- #ifndef __STD_TREE__
- #define __STD_TREE__
- #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
-
- /***************************************************************************
- *
- * tree - Declarations for the Standard Library tree classes
- *
- * $Id: tree,v 1.68 1996/09/30 02:29:07 smithey Exp $
- *
- ***************************************************************************
- *
- * Copyright (c) 1994
- * Hewlett-Packard Company
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Hewlett-Packard Company makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- *
- ***************************************************************************
- *
- * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
- * ALL RIGHTS RESERVED *
- * The software and information contained herein are proprietary to, and
- * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
- * intends to preserve as trade secrets such software and information.
- * This software is furnished pursuant to a written license agreement and
- * may be used, copied, transmitted, and stored only in accordance with
- * the terms of such license and with the inclusion of the above copyright
- * notice. This software and information or any other copies thereof may
- * not be provided or otherwise made available to any other person.
- *
- * Notwithstanding any other lease or license that may pertain to, or
- * accompany the delivery of, this computer software and information, the
- * rights of the Government regarding its use, reproduction and disclosure
- * are as set forth in Section 52.227-19 of the FARS Computer
- * Software-Restricted Rights clause.
- *
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 252.227-7013.
- * Contractor/Manufacturer is Rogue Wave Software, Inc.,
- * P.O. Box 2328, Corvallis, Oregon 97339.
- *
- * This computer software and information is distributed with "restricted
- * rights." Use, duplication or disclosure is subject to restrictions as
- * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
- * Computer Software-Restricted Rights (April 1985)." If the Clause at
- * 18-52.227-74 "Rights in Data General" is specified in the contract,
- * then the "Alternate III" clause applies.
- *
- **************************************************************************/
-
- /*
- **
- ** Red-black tree class, designed for use in implementing STL
- ** associative containers (set, multiset, map, and multimap). The
- ** insertion and deletion algorithms are based on those in Cormen,
- ** Leiserson, and Rivest, Introduction to Algorithms (MIT Press, 1990),
- ** except that:
- **
- ** (1) the header cell is maintained with links not only to the root
- ** but also to the leftmost node of the tree, to enable constant time
- ** begin(), and to the rightmost node of the tree, to enable linear time
- ** performance when used with the generic set algorithms (set_union,
- ** etc.);
- **
- ** (2) when a node being deleted has two children its successor node is
- ** relinked into its place, rather than copied, so that the only
- ** iterators invalidated are those referring to the deleted node.
- **
- */
-
- #include <stdcomp.h>
-
- #ifndef _RWSTD_HEADER_REQUIRES_HPP
- #include <algorithm>
- #include <iterator>
- #else
- #include <algorithm.hpp>
- #include <iterator.hpp>
- #endif
-
- #ifdef _RWSTD_MULTI_THREAD
- #include <rw/stdmutex.h>
- #endif
-
- #ifndef _RWSTD_NO_NAMESPACE
- namespace __rwstd {
- using namespace std;
- #endif
-
- #ifndef rb_tree
- #define rb_tree rb_tree
- #endif
-
- //
- // And a mutex to ensure NIL gets set properly for each type of tree.
- //
- #ifdef _RWSTD_MULTI_THREAD
- extern _RWSTDMutex _RWSTDExport __stl_tree_mutex;
- #endif
-
- template <class Key, class Value, class KeyOfValue,
- class Compare, class Allocator>
- class rb_tree
- {
- protected:
-
- enum color_type { rb_red, rb_black };
-
- struct rb_tree_node;
- friend struct rb_tree_node;
-
- #ifdef _RWSTD_ALLOCATOR
- typedef _TYPENAME Allocator::rebind<void>::other::pointer void_pointer;
- typedef _TYPENAME Allocator::rebind<Value>::other value_alloc_type;
- typedef _TYPENAME Allocator::rebind<Key>::other key_alloc_type;
- typedef _TYPENAME Allocator::rebind<rb_tree_node>::other node_alloc_type;
- #else
- typedef allocator_interface<Allocator,Value> value_alloc_type;
- typedef allocator_interface<Allocator,Key> key_alloc_type;
- typedef allocator_interface<Allocator,rb_tree_node> node_alloc_type;
- typedef value_alloc_type::void_pointer void_pointer;
- #endif
-
- struct rb_tree_node
- {
- #if defined(__WIN32__) || defined(__WIN16__)
- bool isNIL;
- #endif
- ~rb_tree_node() { ; }
- color_type color_field;
- void_pointer parent_link;
- void_pointer left_link;
- void_pointer right_link;
- Value value_field;
- };
-
- typedef _TYPENAME value_alloc_type::pointer pointer;
- typedef _TYPENAME value_alloc_type::const_pointer const_pointer;
- typedef _TYPENAME key_alloc_type::const_reference const_key_reference;
-
- #ifdef __WIN16__
- static rb_tree_node theNilNode;
- #endif
-
- public:
-
- typedef Key key_type;
- typedef Value value_type;
- typedef Allocator allocator_type;
-
- #ifndef _RWSTD_NO_COMPLICATED_TYPEDEF
- typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE size_type;
- typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE difference_type;
- typedef _TYPENAME value_alloc_type::reference reference;
- typedef _TYPENAME value_alloc_type::const_reference const_reference;
- #else
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef Value& reference;
- typedef const Value& const_reference;
- #endif //_RWSTD_NO_COMPLICATED_TYPEDEF
-
- typedef _TYPENAME node_alloc_type::pointer link_type;
-
- protected:
- allocator_type the_allocator;
- size_type buffer_size;
-
- struct rb_tree_node_buffer;
- friend struct rb_tree_node_buffer;
-
- struct rb_tree_node_buffer
- {
- ~rb_tree_node_buffer() { ; }
- void_pointer next_buffer;
- size_type size;
- link_type buffer;
- };
-
- static bool isNil(const link_type& l)
- {
- #if defined(__WIN32__) || defined(__WIN16__)
- if ((*l).isNIL)
- return true;
- return false;
- #else
- return l == NIL;
- #endif
- }
-
- public:
-
- #ifdef _RWSTD_ALLOCATOR
- typedef _TYPENAME allocator_type::rebind<rb_tree_node_buffer>::other buffer_alloc_type;
- #else
- typedef allocator_interface<Allocator,rb_tree_node_buffer> buffer_alloc_type;
- #endif
- typedef buffer_alloc_type::pointer buffer_pointer;
-
- protected:
- buffer_pointer buffer_list;
- link_type free_list;
- link_type next_avail;
- link_type last;
-
- void add_new_buffer ()
- {
- buffer_pointer tmp = buffer_alloc_type(the_allocator).allocate(_RWSTD_STATIC_CAST(size_type,1),buffer_list);
- tmp->buffer = node_alloc_type(the_allocator).allocate(buffer_size,last);
- tmp->next_buffer = buffer_list;
- tmp->size = buffer_size;
- buffer_list = tmp;
- next_avail = buffer_list->buffer;
- last = next_avail + buffer_size;
- }
- void deallocate_buffers ();
-
- //
- // Return a node from the free list or new storage
- //
- link_type get_link()
- {
- link_type tmp = free_list;
- link_type tmp2 = free_list ?
- (free_list = _RWSTD_STATIC_CAST(link_type,(free_list->right_link)), tmp)
- : (next_avail == last ? (add_new_buffer(), next_avail++)
- : next_avail++);
- #if defined(__WIN32__) || defined(__WIN16__)
- tmp2->isNIL = false;
- #endif
- return tmp2;
- }
-
- //
- // Return a node from the free list or new storage with
- // the Value v constructed on it. Every call to get_node
- // must eventually be followed by a call to put_node.
- //
- link_type get_node (const Value& v)
- {
- link_type tmp2 = get_link();
- value_alloc_type va(the_allocator);
- va.construct(va.address(value(tmp2)),v);
- return tmp2;
- }
- link_type get_node ()
- {
- return get_link();
- }
-
- //
- // Return a node to the free list and destroy the value in it.
- //
- void put_node (link_type p, bool do_destroy = true)
- {
- p->right_link = free_list;
- if (do_destroy)
- {
- value_alloc_type va(the_allocator);
- va.destroy(va.address(value(p)));
- }
- free_list = p;
- }
-
- protected:
-
- link_type header;
- link_type& root () { return parent(header); }
- link_type& root () const { return parent(header); }
- link_type& leftmost () { return left(header); }
- link_type& leftmost () const { return left(header); }
- link_type& rightmost () { return right(header); }
- link_type& rightmost () const { return right(header); }
-
- size_type node_count; // Keeps track of size of tree.
- bool insert_always; // Controls whether an element already in the
- // tree is inserted again.
- Compare key_compare;
-
- static link_type NIL;
- #ifndef __WIN16__
- static size_type number_of_trees;
- #endif
-
- static link_type& left (link_type x)
- {
- return _RWSTD_REINTERPRET_CAST(link_type&,((*x).left_link));
- }
- static link_type& right (link_type x)
- {
- return _RWSTD_REINTERPRET_CAST(link_type&,((*x).right_link));
- }
- static link_type& parent (link_type x)
- {
- return _RWSTD_REINTERPRET_CAST(link_type&,((*x).parent_link));
- }
- static reference value (link_type x) { return (*x).value_field; }
- static const_key_reference key (link_type x)
- {
- return KeyOfValue()(value(x));
- }
- static color_type& color (link_type x)
- {
- return _RWSTD_STATIC_CAST(color_type&,(*x).color_field);
- }
- static link_type minimum (link_type x)
- {
- while (!isNil(left(x))) x = left(x);
- return x;
- }
- static link_type maximum (link_type x)
- {
- while (!isNil(right(x))) x = right(x);
- return x;
- }
-
- public:
-
- class iterator;
- friend class iterator;
- class const_iterator;
- friend class const_iterator;
-
- class iterator : public bidirectional_iterator<Value, difference_type>
- {
- friend class rb_tree<Key, Value, KeyOfValue, Compare, Allocator>;
- friend class const_iterator;
-
- protected:
-
- link_type node;
- iterator (link_type x) : node(x) {}
-
- public:
-
- iterator () {}
- bool operator== (const iterator& y) const { return node == y.node; }
- bool operator!= (const iterator& y) const { return node != y.node; }
- reference operator* () const { return value(node); }
- iterator& operator++ ()
- {
- if (!isNil(right(node)))
- {
- node = right(node);
- while (!isNil(left(node))) node = left(node);
- }
- else
- {
- link_type y = parent(node);
- while (node == right(y))
- {
- node = y; y = parent(y);
- }
- if (right(node) != y) // Necessary because of rightmost.
- node = y;
- }
- return *this;
- }
- iterator operator++ (int)
- {
- iterator tmp = *this; ++*this; return tmp;
- }
- iterator& operator-- ()
- {
- if (color(node) == rb_red && parent(parent(node)) == node)
- //
- // Check for header.
- //
- node = right(node); // Return rightmost.
- else if (!isNil(left(node)))
- {
- link_type y = left(node);
- while (!isNil(right(y))) y = right(y);
- node = y;
- }
- else
- {
- link_type y = parent(node);
- while (node == left(y))
- {
- node = y; y = parent(y);
- }
- node = y;
- }
- return *this;
- }
- iterator operator-- (int)
- {
- iterator tmp = *this; --*this; return tmp;
- }
-
- }; // End of definition of iterator.
-
- class const_iterator
- : public bidirectional_iterator<Value,difference_type>
- {
- friend class rb_tree<Key, Value, KeyOfValue, Compare, Allocator>;
- friend class iterator;
-
- protected:
-
- link_type node;
- const_iterator (link_type x) : node(x) {}
-
- public:
-
- const_iterator () {}
- const_iterator (const iterator& x) : node(x.node) {}
- bool operator== (const const_iterator& y) const
- {
- return node == y.node;
- }
- bool operator!= (const const_iterator& y) const
- {
- return node != y.node;
- }
- const_reference operator* () const { return value(node); }
- const_iterator& operator++ ()
- {
- if (!isNil(right(node)))
- {
- node = right(node);
- while (!isNil(left(node))) node = left(node);
- }
- else
- {
- link_type y = parent(node);
- while (node == right(y))
- {
- node = y; y = parent(y);
- }
- if (right(node) != y) // Necessary because of rightmost.
- node = y;
- }
- return *this;
- }
- const_iterator operator++ (int)
- {
- const_iterator tmp = *this; ++*this; return tmp;
- }
- const_iterator& operator-- ()
- {
- if (color(node) == rb_red && parent(parent(node)) == node)
- //
- // Check for header.
- //
- node = right(node); // return rightmost
- else if (!isNil(left(node)))
- {
- link_type y = left(node);
- while (!isNil(right(y))) y = right(y);
- node = y;
- }
- else
- {
- link_type y = parent(node);
- while (node == left(y))
- {
- node = y; y = parent(y);
- }
- node = y;
- }
- return *this;
- }
- const_iterator operator-- (int)
- {
- const_iterator tmp = *this; --*this; return tmp;
- }
- }; // End of definition of const_iterator.
-
- #ifndef _RWSTD_NO_NAMESPACE
- typedef ::std::reverse_bidirectional_iterator<iterator, value_type,
- reference,pointer, difference_type>
- reverse_iterator;
- typedef ::std::reverse_bidirectional_iterator<const_iterator, value_type,
- const_reference, const_pointer, difference_type>
- const_reverse_iterator;
- #else
- typedef ::reverse_bidirectional_iterator<iterator, value_type,
- reference,pointer, difference_type>
- reverse_iterator;
- typedef ::reverse_bidirectional_iterator<const_iterator, value_type,
- const_reference, const_pointer, difference_type>
- const_reverse_iterator;
- #endif
-
- private:
-
- iterator __insert (link_type x, link_type y, const value_type& v);
- link_type __copy (link_type x, link_type p);
- void __erase (link_type x);
- void init ()
- {
- buffer_size = 1;
- buffer_list = 0;
- free_list = next_avail = last = 0;
-
- {
- #ifdef _RWSTD_MULTI_THREAD
- _RWSTDGuard guard(__stl_tree_mutex);
- #endif
- #ifndef __WIN16__
- ++number_of_trees;
- #endif
- if (NIL == 0)
- {
- #ifdef __WIN16__
- NIL = &theNilNode;
- #else
- NIL = node_alloc_type(the_allocator).allocate(_RWSTD_STATIC_CAST(size_type,1),last);
- #endif
- color(NIL) = rb_black;
- parent(NIL) = 0;
- left(NIL) = 0;
- right(NIL) = 0;
- #if defined(__WIN32__) || defined(__WIN16__)
- (*NIL).isNIL = true;
- #endif
- }
- }
- header = get_node();
- color(header) = rb_red; // Used to distinguish header from root
- // in iterator.operator++.
- root() = NIL;
- leftmost() = header;
- rightmost() = header;
- buffer_size =
- 1 >__RWSTD::__rw_allocation_size((value_type*)0,(size_type)0) ? 1 : __RWSTD::__rw_allocation_size((value_type*)0,(size_type)0);
- //max((size_type)1,__RWSTD::__rw_allocation_size((value_type*)0,(size_type)0));
- }
- public:
-
- rb_tree (const Compare& _RWSTD_COMP _RWSTD_DEFAULT_ARG(Compare()), bool always _RWSTD_DEFAULT_ARG(true),
- const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(always), the_allocator(alloc)
- {
- init();
- }
-
- #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
- rb_tree (void)
- : node_count(0), key_compare(Compare()),
- insert_always(true), the_allocator(Allocator())
- {
- init();
- }
-
- rb_tree (const Compare& _RWSTD_COMP)
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(true), the_allocator(Allocator())
- {
- init();
- }
-
- rb_tree (const Compare& _RWSTD_COMP , bool always = true)
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(always), the_allocator(Allocator())
- {
- init();
- }
- #endif
-
- #ifndef _RWSTD_NO_MEMBER_TEMPLATES
- template<class InputIterator>
- rb_tree (InputIterator first, InputIterator last,
- const Compare& comp = Compare(), bool always = true,
- const Allocator& alloc = Allocator())
- : node_count(0), key_compare(comp),
- insert_always(always), the_allocator(alloc)
- {
- init();
- insert(first, last);
- }
- #else
- rb_tree (const value_type* first, const value_type* last,
- const Compare& _RWSTD_COMP _RWSTD_DEFAULT_ARG(Compare()), bool always _RWSTD_DEFAULT_ARG(true),
- const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(always), the_allocator(alloc)
- {
- init();
- insert(first, last);
- }
- rb_tree (const_iterator first, const_iterator last,
- const Compare& _RWSTD_COMP _RWSTD_DEFAULT_ARG(Compare()), bool always _RWSTD_DEFAULT_ARG(true),
- const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(always), the_allocator(alloc)
- {
- init();
- insert(first, last);
- }
-
- #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
- rb_tree (const value_type* first, const value_type* last,
- const Compare& _RWSTD_COMP _RWSTD_DEFAULT_ARG(Compare()))
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(true), the_allocator(Allocator())
- {
- init();
- insert(first, last);
- }
-
- rb_tree (const value_type* first, const value_type* last,
- const Compare& _RWSTD_COMP _RWSTD_DEFAULT_ARG(Compare()), bool always _RWSTD_DEFAULT_ARG(true))
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(always), the_allocator(Allocator())
- {
- init();
- insert(first, last);
- }
-
- rb_tree (const_iterator first, const_iterator last,
- const Compare& _RWSTD_COMP _RWSTD_DEFAULT_ARG(Compare()))
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(true), the_allocator(Allocator())
- {
- init();
- insert(first, last);
- }
-
- rb_tree (const_iterator first, const_iterator last,
- const Compare& _RWSTD_COMP _RWSTD_DEFAULT_ARG(Compare()), bool always _RWSTD_DEFAULT_ARG(true))
- : node_count(0), key_compare(_RWSTD_COMP),
- insert_always(always), the_allocator(Allocator())
- {
- init();
- insert(first, last);
- }
- #endif
-
- #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
- rb_tree (const value_type* first, const value_type* last)
- : node_count(0), key_compare(Compare()),
- insert_always(true), the_allocator(Allocator())
- {
- init();
- insert(first, last);
- }
-
- rb_tree (const_iterator first, const_iterator last)
- : node_count(0), key_compare(Compare()),
- insert_always(true), the_allocator(Allocator())
- {
- init();
- insert(first, last);
- }
-
- #endif
- #endif
-
- rb_tree (const rb_tree<Key,Value,KeyOfValue,Compare,Allocator>& x,
- bool always = true)
- : node_count(x.node_count), key_compare(x.key_compare),
- insert_always(always)
- {
- the_allocator = x.get_allocator();
- {
- #ifdef _RWSTD_MULTI_THREAD
- _RWSTDGuard guard(__stl_tree_mutex);
- #endif
- #ifndef __WIN16__
- ++number_of_trees;
- #endif
- }
- buffer_size = 1;
- buffer_list = 0;
- free_list = next_avail = last = 0;
- header = get_node();
- buffer_size =
- 1 > __RWSTD::__rw_allocation_size((value_type*)0,(size_type)0) ?
- 1 : __RWSTD::__rw_allocation_size((value_type*)0,(size_type)0);
- //max((size_type)1,__RWSTD::__rw_allocation_size((value_type*)0,(size_type)0));
- color(header) = rb_red;
- root() = __copy(x.root(), header);
- if (isNil(root()))
- {
- leftmost() = header; rightmost() = header;
- }
- else
- {
- leftmost() = minimum(root()); rightmost() = maximum(root());
- }
- }
- ~rb_tree ()
- {
- erase(begin(), end());
- put_node(header,false);
- deallocate_buffers();
- #ifndef __WIN16__
- #ifdef _RWSTD_MULTI_THREAD
- _RWSTDGuard guard(__stl_tree_mutex);
- #endif
- if (--number_of_trees == 0)
- {
- node_alloc_type(the_allocator).deallocate(NIL,1);
- NIL = 0;
- }
- #endif
- }
-
- rb_tree<Key, Value, KeyOfValue, Compare, Allocator>&
- operator= (const rb_tree<Key, Value, KeyOfValue, Compare, Allocator>& x);
-
- Compare key_comp () const { return key_compare; }
- allocator_type get_allocator() const
- {
- return the_allocator;
- }
-
- iterator begin () { return leftmost(); }
- const_iterator begin () const { return leftmost(); }
- iterator end () { return header; }
- const_iterator end () const { return header; }
-
- reverse_iterator rbegin ()
- {
- reverse_iterator tmp(end()); return tmp;
- }
- const_reverse_iterator rbegin () const
- {
- const_reverse_iterator tmp(end()); return tmp;
- }
- reverse_iterator rend ()
- {
- reverse_iterator tmp(begin()); return tmp;
- }
- const_reverse_iterator rend () const
- {
- const_reverse_iterator tmp(begin()); return tmp;
- }
-
- bool empty () const { return node_count == 0; }
- size_type size () const { return node_count; }
- size_type max_size () const
- {
- return node_alloc_type(the_allocator).max_size();
- }
- void swap (rb_tree<Key, Value, KeyOfValue, Compare, Allocator>& t)
- {
- #ifndef _RWSTD_NO_NAMESPACE
- std::swap(the_allocator, t.the_allocator);
- std::swap(buffer_list, t.buffer_list);
- std::swap(free_list, t.free_list);
- std::swap(next_avail, t.next_avail);
- std::swap(last, t.last);
- std::swap(header, t.header);
- std::swap(node_count, t.node_count);
- std::swap(insert_always, t.insert_always);
- std::swap(key_compare, t.key_compare);
- #else
- ::swap(the_allocator, t.the_allocator);
- ::swap(buffer_list, t.buffer_list);
- ::swap(free_list, t.free_list);
- ::swap(next_avail, t.next_avail);
- ::swap(last, t.last);
- ::swap(header, t.header);
- ::swap(node_count, t.node_count);
- ::swap(insert_always, t.insert_always);
- ::swap(key_compare, t.key_compare);
- #endif
- }
-
- typedef pair<iterator, bool> pair_iterator_bool;
- //
- // typedef done to get around compiler bug.
- //
-
- #ifndef _RWSTD_NO_RET_TEMPLATE
- pair<iterator,bool> insert (const value_type& x);
- #else
- pair_iterator_bool insert (const value_type& x);
- #endif
-
- iterator insert (iterator position, const value_type& x);
-
- #ifndef _RWSTD_NO_MEMBER_TEMPLATES
- template<class Iterator>
- void insert (Iterator first, Iterator last);
- #else
- void insert (const_iterator first, const_iterator last);
- void insert (const value_type* first, const value_type* last);
- #endif
-
- iterator erase (iterator position);
- size_type erase (const key_type& x);
- iterator erase (iterator first, iterator last);
- void erase (const key_type* first, const key_type* last);
-
- iterator find (const key_type& x);
- const_iterator find (const key_type& x) const;
- size_type count (const key_type& x) const;
- iterator lower_bound (const key_type& x);
- const_iterator lower_bound (const key_type& x) const;
- iterator upper_bound (const key_type& x);
- const_iterator upper_bound (const key_type& x) const;
-
- typedef pair<iterator, iterator> pair_iterator_iterator;
- //
- // typedef done to get around compiler bug.
- //
- #ifndef _RWSTD_NO_RET_TEMPLATE
- pair<iterator,iterator> equal_range (const key_type& x);
- #else
- pair_iterator_iterator equal_range (const key_type& x);
- #endif
-
- typedef pair<const_iterator, const_iterator> pair_citerator_citerator;
- #ifndef _RWSTD_NO_RET_TEMPLATE
- pair<const_iterator, const_iterator> equal_range (const key_type& x) const;
- #else
- pair_citerator_citerator equal_range (const key_type& x) const;
- #endif
- inline void rotate_left (link_type x);
- inline void rotate_right (link_type x);
-
- // Query and set the allocation size
- size_type allocation_size() { return buffer_size; }
- size_type allocation_size(size_type new_size)
- {
- size_type tmp = buffer_size;
- buffer_size = 1 > new_size ? 1 : new_size; //max((size_type)1,new_size);
- return tmp;
- }
- };
-
-
- //
- // Inline functions
- //
-
- template <class Key, class Value, class KeyOfValue,
- class Compare, class Allocator>
- inline bool operator== (const rb_tree<Key, Value, KeyOfValue, Compare, Allocator>& x,
- const rb_tree<Key, Value, KeyOfValue, Compare, Allocator>& y)
- {
- return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
- }
-
- template <class Key, class Value, class KeyOfValue,
- class Compare, class Allocator>
- inline bool operator< (const rb_tree<Key, Value, KeyOfValue, Compare, Allocator>& x,
- const rb_tree<Key, Value, KeyOfValue, Compare, Allocator>& y)
- {
- return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
- }
-
- template <class Key, class Value, class KeyOfValue, class Compare, class Allocator>
- inline void
- rb_tree<Key, Value, KeyOfValue, Compare, Allocator>::rotate_left (link_type x)
- {
- link_type y = right(x);
- right(x) = left(y);
- if (!isNil(left(y)))
- parent(left(y)) = x;
- parent(y) = parent(x);
- if (x == root())
- root() = y;
- else if (x == left(parent(x)))
- left(parent(x)) = y;
- else
- right(parent(x)) = y;
- left(y) = x;
- parent(x) = y;
- }
-
-
- template <class Key, class Value, class KeyOfValue,
- class Compare, class Allocator>
- inline void
- rb_tree<Key, Value, KeyOfValue, Compare, Allocator>::rotate_right (link_type x)
- {
- link_type y = left(x);
- left(x) = right(y);
- if (!isNil(right(y)))
- parent(right(y)) = x;
- parent(y) = parent(x);
- if (x == root())
- root() = y;
- else if (x == right(parent(x)))
- right(parent(x)) = y;
- else
- left(parent(x)) = y;
- right(y) = x;
- parent(x) = y;
- }
-
- #ifndef _RWSTD_NO_NAMESPACE
- }
- #endif
-
- #ifdef _RWSTD_NO_TEMPLATE_REPOSITORY
- #include <rw/tree.cc>
- #endif
-
- #pragma option pop
- #endif /* __STD_TREE__ */
-